import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import { createHtmlPlugin } from "vite-plugin-html";
import { proTitle } from './baseUrl'

// https://vite.dev/config/
export default defineConfig({
  base: './',
  server: {
    host: '0.0.0.0',
    port: 9001,
    open: true,
    // proxy: {
    //   '/api': {
    //     target: 'http://10.0.8.9:9000',
    //     // secure: false, // 请求是否为https
    //     changeOrigin: true,
    //     // rewrite:(path)=>path.replace(/^\/api/,'') //api替换为'',
    //   }
    // }
  },
  // 设置scss的api类型为modern-compiler
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler'
      }
    }
  },
  plugins: [
    vue(),
    createHtmlPlugin({
      inject: {
        data: {
          //将环境变量 VITE_APP_TITLE 赋值给 title 方便 html页面使用 title 获取系统标题
          // title: getViteEnv(mode, "VITE_APP_TITLE"),
          title: proTitle
        },
      },
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
})
